package cn.lyf.myblog.handler;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class ControllerExceptionHandler {

    
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @ExceptionHandler(Exception.class)
    public ModelAndView exceptionHandler(HttpServletRequest req, Exception e) {
        logger.error("Request : {},Exception : {}", req.getRequestURI(), e);
        ModelAndView mv = new ModelAndView();
        mv.addObject("url", req.getRequestURI());
        mv.addObject("error", e);
        mv.setViewName("error/error");
        return mv;
    }
}
